package com.lgd.experiment;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * Created by 299174105 on 2017/8/9.
 */
public class Java8String {
    class Person{
        private String name;
        private String age;
        public String getName() {
            return name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public void setName(String name) {
            this.name = name;

        }

        public Person(String name, String age) {
            this.name = name;
            this.age = age;
        }

        public Person() {
        }

    }
    public static   String getPersonName(Person person){
        Optional<String> personName = Optional.ofNullable(person).map(Person::getName);
        return personName.orElse(null);
    }
    public List<Person> getPerson(){
        ArrayList<Person> persons = new ArrayList<>();
        Person person = new Person();
        person.setAge("10");
        person.setName("tom");
        persons.add(person);
        persons.add(person);
        persons.add(person);
        persons.add(person);
        return persons;
    }
    public static void main(String[] args) {
        String s = String.join(",", "tom", "jerry", "paul", "dave");
        System.out.println(s);
        //tom,jerry,paul,dave
        System.out.println(getPersonName(null));
        int[] a ={1,2,3,4,5};
        System.out.println(a[1]);
       int[] b=new int[]{1,2,3,4};
        System.out.println(b[0]);
        Java8String java8String = new Java8String();
        for (int i = 0; i < 5 ; i++) {

        }
        List<Person> person =  java8String.getPerson();
        //关闭重复对象引用化的问题
        System.out.println(JSON.toJSONString(person, SerializerFeature.DisableCircularReferenceDetect));
    }
}
